//ComplexPanel.java
//Timothy Grant
//CS1410
//Calculator 1410
//Final Version

package calculator1410;

import javax.swing.JFrame;
import javax.swing.JTextArea;
import numbers.ComplexNumber;
import evaluateexpression.ExpressionEvaluator;

public class ComplexPanel extends NumberPanel {

    @Override
    public void toggleInfo() {
        String helpMessage = "Enter a complex number using brackets: [1+2.5i]\n\n"
                + "The following operations are supported: \n\n"
                + "     Addition: [1+2i]+[2-2.5i] = [3.0+-0.5i]\n"
                + "     Subtraction: [1+2i]-[2-2.5i] = [-1.0+4.5i]\n"
                + "     Multiplication: [1+2i]*[2-2.5i] = [7.0+1.5i]\n"
                + "     Division: [1+2i]/[2-2.5i] = [-0.292...+0.634...i]\n\n"
                + "Parentheses are supported";


        String helpHeader = "Complex Number Help";

        JFrame helpFrame = new JFrame(helpHeader);
        JTextArea helpExp = new JTextArea(helpMessage);
        //helpExp.setFont( helpFont );
        helpFrame.add(helpExp);
        helpFrame.setResizable(false);
        helpFrame.pack();
        //helpFrame.setSize(320, 270);
        helpFrame.setVisible(true);
    }

    @Override
    public void equals() {
        ComplexNumber complex = new ComplexNumber(0, 0);
        String equal;
        if (!expressionArea.getText().contains("=")) {
            equal = ExpressionEvaluator.evalExpression(
                    expressionArea.getText(), complex);
            expressionArea.setText(expressionArea.getText() + "\n=\n" + equal);
        } else {
            int equalIndex = expressionArea.getText().indexOf("=");
            equal = ExpressionEvaluator.evalExpression(
                    expressionArea.getText().substring(++equalIndex), complex);
            expressionArea.setText(expressionArea.getText().substring(++equalIndex)
                    + "\n=\n" + equal);
        }
    }

    @Override
    public void newEquals() {
    }
}
